#include "Common.hpp"


class CentralCache
{
    public:
        static CentralCache* GetInstance()
        {
            return &_sInst;
        }
        size_t FetchRangeObj(void*& start , void*& end , size_t n , size_t size)
        {
            //先算你要哪个桶
            size_t index = SizeClass::Index(size);
            _spanLists[index]._mutex.lock();
            Span* span = GetOneSpan(_spanLists[index],size);
            assert(span);
            assert(span->_freeList);
            start = span->_freeList;
            end = start;
            size_t actualNum = 1;
            for(int i = 0 ; i < n - 1 && FreeList::NextObj(end) ; ++i)
            {
                end = FreeList::NextObj(end);
                ++actualNum;
            }
            span->_freeList = FreeList::NextObj(end);
            FreeList::NextObj(end) = nullptr;
            _spanLists[index]._mutex.unlock();
            return actualNum;
        }
        Span* GetOneSpan(SpanList& list , size_t size) //获取一个非空的Span
        {
            return nullptr;
        }
    private:
        SpanList _spanLists[NFREELISTS];
    private:
        CentralCache(){} //饿汉模式
        CentralCache(const CentralCache& self) = delete;

        static CentralCache _sInst;
};
CentralCache CentralCache::_sInst;